﻿Imports System.Windows.Forms
Imports FastColoredTextBoxNS.FastColoredTextBox

Public Class Main2

    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
        ' Create a new instance of the child form.
        Dim ChildForm As New System.Windows.Forms.Form
        Dim richtextbox As New FastColoredTextBoxNS.FastColoredTextBox
        Dim tabs As New System.Windows.Forms.TabControl
        Dim lbl As New System.Windows.Forms.Label
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        m_ChildFormNumber += 1
        richtextbox.Name = "RTB_" & m_ChildFormNumber
        ChildForm.Text = "DevBox " & m_ChildFormNumber
        ChildForm.Controls.Add(richtextbox)
        richtextbox.Dock = DockStyle.Fill
        ChildForm.Controls.Add(tabs)
        tabs.Alignment = TabAlignment.Bottom
        tabs.TabPages.Add("1", "Code")
        tabs.TabPages.Add("2", "Design")
        tabs.Dock = DockStyle.Fill
        richtextbox.Parent = tabs.TabPages.Item("1")
        richtextbox.Dock = DockStyle.Fill
        richtextbox.Language = FastColoredTextBoxNS.Language.VB
        ChildForm.Controls.Add(lbl)
        lbl.Parent = tabs.TabPages.Item("2")
        lbl.Dock = DockStyle.Fill
        lbl.Text = "404. Sorry :P. Design view will be here soon. We promise."
        ChildForm.Show()
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = OpenFileDialog.FileName
            ' TODO: Add code here to open the file.
        End If
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" 

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: Add code here to save the current contents of the form to a file.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
        Startup.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CutToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CopyToolStripMenuItem.Click
        ' Use My.Computer.Clipboard to insert the selected text or images into the clipboard
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles PasteToolStripMenuItem.Click
        'Use My.Computer.Clipboard.GetText() or My.Computer.Clipboard.GetData to retrieve information from the clipboard.
    End Sub

    Private Sub ToolBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolBarToolStripMenuItem.Click
        Me.ToolStrip.Visible = Me.ToolBarToolStripMenuItem.Checked
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub Main2_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Startup.Close()
    End Sub

    Private Sub Main2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Text = "DevBox - " + Project.project_name
        Dim fs As New FS
        For Each foundFile As String In My.Computer.FileSystem.GetFiles(fs.Startup + "Projects\" + Project.project_name)
            If (foundFile.EndsWith(".designer.vb")) Then
                ' Create a new instance of the child form.
                Dim ChildForm As New System.Windows.Forms.Form
                'Dim richtextbox As New System.Windows.Forms.RichTextBox
                Dim richtextbox As New FastColoredTextBoxNS.FastColoredTextBox
                Dim tabs As New System.Windows.Forms.TabControl
                Dim lbl As New System.Windows.Forms.Label
                ' Make it a child of this MDI form before showing it.
                ChildForm.MdiParent = Me
                m_ChildFormNumber += 1
                richtextbox.Name = "RTB_" & m_ChildFormNumber
                ChildForm.Text = "DevBox " & m_ChildFormNumber
                ChildForm.Controls.Add(richtextbox)
                ChildForm.Controls.Add(tabs)
                tabs.Alignment = TabAlignment.Bottom
                tabs.TabPages.Add("1", "Code")
                tabs.TabPages.Add("2", "Design")
                tabs.Dock = DockStyle.Fill
                richtextbox.Parent = tabs.TabPages.Item("1")
                richtextbox.Dock = DockStyle.Fill
                richtextbox.Language = FastColoredTextBoxNS.Language.VB
                richtextbox.Text = System.IO.File.ReadAllText(foundFile)
                ChildForm.Controls.Add(lbl)
                lbl.Parent = tabs.TabPages.Item("2")
                lbl.Dock = DockStyle.Fill
                lbl.Text = "404. Sorry :P. Design view will be here soon. We promise."
                ChildForm.Show()
            End If
        Next
    End Sub

    Private Sub AboutToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        'MessageBox.Show("Developed by Josh Miles (UniqOS) & Aolko")
        about.Show()
    End Sub

    Private Sub Debug_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Debug.Click

    End Sub
End Class
